<?php

namespace app\common\service;

use app\common\model\ActionLog;
use app\common\model\AdminActionLog;
use think\Exception;

class AdminActionLogService
{

    /**UserPrivilegeLogic
     * 列表
     */
    static public function cmsList($request, $export = 0)
    {
        try {
            $request = array_filter($request);
            $result = ActionLog::build()
                               ->dateBetween('create_time')
                               ->equal('username');

            if (isset($request['keyword_search'])) {
                $result = $result->whereLike('admin_name|admin_ip|menu_name|operation', sprintf('%%%s%%', $request['keyword_search']));
            }

            $result = $result->order('create_time desc')
                             ->where('is_deleted', 0)
                             ->_paginate();
            return $result;
        } catch (Exception $e) {
            return ['msg' => $e->getMessage()];
        }
    }

    /**
     * 删除
     */
    static public function cmsDelete($id)
    {
        try {
            if ($id !== 'all') {
                return AdminActionLog::build()
                                     ->where('id', $id)
                                     ->setField('is_deleted', 1);
            } else {
                return AdminActionLog::build()
                                     ->where('is_deleted', 0)
                                     ->setField('is_deleted', 1);
            }
        } catch (Exception $e) {
            return ['msg' => $e->getMessage()];
        }
    }


}